package coffeebar;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Cashout extends JPanel {

	MoneyCountingArea moneyCountingArea;
	private static QuestionPanel question1;
	private static QuestionPanel question2;
	private static QuestionPanel question3;
	private static QuestionPanel comments;
	private static JLabel q1txt;
	private static JLabel q2txt;
	private static JLabel q3txt;
	private static JButton yes1;
	private static JButton yes2;
	private static JButton yes3;
	private static JButton no1;
	private static JButton no2;
	private static JButton no3;
	private static JButton submitComment;
	private static JTextArea commentArea;

	public Cashout() {

		moneyCountingArea = new MoneyCountingArea();

		q1txt = new JLabel("Have you mopped the floor?");
		q2txt = new JLabel("Are there 3 boxes of ice-cream in the freezer?");
		q3txt = new JLabel("Is the washing mashine running?");

		question1 = new QuestionPanel();
		question2 = new QuestionPanel();
		question3 = new QuestionPanel();

		yes2 = new JButton();
		yes3 = new JButton();

		no2 = new JButton();
		no3 = new JButton();
		submitComment = new JButton();
		commentArea = new JTextArea();

		// question number one

		question1.setLayout(new BoxLayout(question1, BoxLayout.X_AXIS));
		yes1 = new JButton("yes");
		yes1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StatusBar.setMessage("Good.");
				question2.setGrayed(false);
			}
		});

		no1 = new JButton("no");
		no1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StatusBar.setMessage("WTF? Mop the flow immediately.");
			}
		});

		question1.add(q1txt, BorderLayout.WEST);
		question1.add(Box.createHorizontalGlue());
		question1.add(yes1, BorderLayout.EAST);
		question1.add(no1);

		// question two
		question2.setLayout(new BoxLayout(question2, BoxLayout.X_AXIS));
		yes2 = new JButton("yes");
		yes2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StatusBar.setMessage("Good.");
				question3.setGrayed(false);
			}
		});

		no2 = new JButton("no");
		no2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StatusBar.setMessage("Right, an email has been sent for you.");
				// TODO make email code
			}
		});

		question2.add(q2txt, BorderLayout.WEST);
		question2.add(Box.createHorizontalGlue());
		question2.add(yes2, BorderLayout.EAST);
		question2.add(no2);

		// question three
		question3.setLayout(new BoxLayout(question3, BoxLayout.X_AXIS));
		yes3 = new JButton("yes");
		yes3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StatusBar.setMessage("Good, now lock up. God bless you.");
				comments.setGrayed(false);
				Controller.quit();
			}
		});

		no3 = new JButton("no");
		no3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StatusBar.setMessage("WTF? Make it run immediately");
				// TODO make email code
			}
		});
		question3.add(q3txt);
		question3.add(Box.createHorizontalGlue());
		question3.add(yes3);
		question3.add(no3);

		// comment panel
		commentArea = new JTextArea();
		submitComment = new JButton("Sumbit and quit");
		submitComment.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO make email code
				StatusBar.setMessage("WTF? Make it run immediately");
				Controller.quit();
			}
		});

		comments = new QuestionPanel();
		comments.setLayout(new BoxLayout(comments, BoxLayout.X_AXIS));
		commentArea.setMaximumSize(new Dimension(500, 150)); // TODO make
		// this pretty!
		commentArea.setPreferredSize(commentArea.getMaximumSize());
		comments.add(commentArea);
		comments.add(submitComment);

		// general panel:
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		moneyCountingArea.setAlignmentX(Component.LEFT_ALIGNMENT);
		question1.setAlignmentX(Component.LEFT_ALIGNMENT);
		question2.setAlignmentX(Component.LEFT_ALIGNMENT);
		question3.setAlignmentX(Component.LEFT_ALIGNMENT);
		this.add(moneyCountingArea);
		this.add(Box.createRigidArea(new Dimension(0, 10)));
		this.add(question1);
		this.add(Box.createRigidArea(new Dimension(0, 10)));
		this.add(question2);
		this.add(Box.createRigidArea(new Dimension(0, 10)));
		this.add(question3);
		// this.add(comments);

		question1.setGrayed(true);
		question2.setGrayed(true);
		question3.setGrayed(true);
		comments.setGrayed(true);
		//FIXME: this is a nasty nasty hack
		moneyCountingArea.money[0].transferFocus();
	}

	public void gotoQuestion1() {
		question1.setGrayed(false);
	}
}